// index.js
// 获取应用实例
import { request } from "../../request/index.js";
const app = getApp()

Page({
  data: {
    imgurl:'../../images/',
    bridgeList:[],
    bridgeName:'',               //桥梁名称
    bridgeDate:'',               //桥梁建设日期
    bridgeMaintain:'',           //养护标段
    bridgeDepartment:'',         //桥梁负责单位
    bridgeType:'',               //桥梁类型
    bridgeState:'',              //桥梁状态
    bridgeContact:'',            //桥梁负责人
    bridgeContactPhone:'',       //桥梁负责人联系电话
    bridgeYear:'',               //桥梁建设年限
    bridgeLength:'',             //桥梁长度
    bridgeWidth:'',              //桥梁宽度
    bridgeArea:'',               //桥梁面积
    bridgeFrontalViewSrc:'',     //桥面正面照链接
    bridgeIViewSrc:'',           //桥面侧面照链接
    scanCode:''      ,            //扫码返回值
    Scan:'扫码',
    search:'生码',
    modalHidden: true,
  },
  // 事件处理函数
  onLoad() {
    
  },
  Scan(){
     //先初始化卡片内容
    this.init()
    wx.scanCode({
      success:(res)=>{
        // success
         //扫码成功将得到的结果复制给scancode
        if(res){
          console.log(res)
          this.data.scanCode=res.result
          console.log(this.data.scanCode)
            //然后向服务器请求数据
          this.getBridgeDate()
          //弹出信息的弹    
        }
        else{
          wx.showToast({
            title:'未找到数据',
            icon:'none'
          })
        }        
      },
      fail: function() {
        wx.showToast({
          title:'扫码失败',
          icon:'none'
        })
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  ///向接口 获取数据
  getBridgeDate(){
     this.data.bridgeList=app.globalData.bridgeList
     if(this.data.bridgeList.length==0){
       wx.showToast({
         title:'数据请求失败',
         icon:"none"
       })
     }
     console.log(this.data.bridgeList)
     this.setData({
        bridgeName:this.data.bridgeList[0].bridgename,
        bridgeDate:this.data.bridgeList[0].builddate,
        bridgeMaintain:this.data.bridgeList[0].section,
        bridgeDepartment:this.data.bridgeList[0].company,
        bridgeType:this.data.bridgeList[0].roadclassdesc,
        bridgeState:this.data.bridgeList[0].buildstatusdesc,
        bridgeContact:this.data.bridgeList[0].companyperson,
        bridgeContactPhone:this.data.bridgeList[0].companycontact,
        bridgeYear:this.data.bridgeList[0].unid,
        bridgeLength:this.data.bridgeList[0].bridgelength,
        bridgeWidth:this.data.bridgeList[0].bridgewidth,
        bridgeArea:this.data.bridgeList[0].bridgearea,
        bridgeFrontalViewSrc:this.data.bridgeList[0].picturefront,
        bridgeIViewSrc:this.data.bridgeList[0].pictureside,
      })
    this.buttonTap()
  },
  //初始化数据
  init:function(){
    var _this=this;
    _this.setData({
      bridgeName:'',               //桥梁名称
      bridgeDate:'',               //桥梁建设日期
      bridgeMaintain:'',           //养护标段
      bridgeDepartment:'',         //桥梁负责单位
      bridgeType:'',               //桥梁类型
      bridgeState:'',              //桥梁状态
      bridgeContact:'',            //桥梁负责人
      bridgeContactPhone:'',       //桥梁负责人联系电话
      bridgeYear:'',               //桥梁建设年限
      bridgeLength:'',             //桥梁长度
      bridgeWidth:'',              //桥梁宽度
      bridgeArea:'',               //桥梁面积
      bridgeFrontalViewSrc:'',     //桥面正面照链接
      bridgeIViewSrc:'',           //桥面侧面照链接
      scanCode:''                  //扫码返回值
    })
  },
  /**
   * 显示弹窗
   */
   buttonTap: function() {
    this.setData({
      modalHidden: false
    })
  },
   /**
   *  点击确认
   */
    modalConfirm: function() {
      // do something
      this.setData({
        modalHidden: true
      })
    },
})
